import axios from "axios";

// Add a request interceptor
axios.interceptors.request.use(
  function (config) {
    // Do something before request is sent
    return config;
  },
  function (error) {
    // Do something with request error
    return Promise.reject(error);
  }
);

// Add a response interceptor
axios.interceptors.response.use(
  function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  },
  function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    let errorStatus = error.response;
    if (errorStatus === "400") {
      alert("请求超时");
    } else if (errorStatus === "500") {
      alert("服务器错误");
    }else if (errorStatus === "404"){
      alert("页面找不到")
    }else if (errorStatus === "502"){
      alert("服务器过载")
    }
    return Promise.reject(error);
  }
);

export let get_list = () => axios.get("/api/list");
export let get_car_list = () => axios.get("/api/carlist");
